package com.spider.admin.controller;


import com.spider.admin.exception.SpiderException;
import com.spider.admin.service.apimarks.ApiMarksService;
import com.spider.admin.store.primary.model.AccountServicePerm;
import com.spider.admin.store.primary.model.ServiceInfo;
import com.spider.admin.store.primary.model.TenantAndAppInfo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequiredArgsConstructor
@Validated
@RequestMapping("/marks")
public class ServiceMarksController {

    @Autowired
    private ApiMarksService apiMarksService;

    @GetMapping("/appList")
    public List<TenantAndAppInfo> queryAllAppTree(@RequestParam(required = false) String tenantId) throws SpiderException {
        return apiMarksService.getAll(tenantId);
    }

    @GetMapping("/serviceList")
    public List<ServiceInfo> queryAllService(@RequestParam String account,@RequestParam(required = false) String gId, @RequestParam(required = false) String type)throws SpiderException{
        return apiMarksService.getServiceList(gId,account,type);
    }

    @GetMapping("/accountServiceList")
    public List<ServiceInfo> queryAccountService(@RequestParam String account,@RequestParam(required = false) String gId, @RequestParam(required = false) String type)throws SpiderException{
        return apiMarksService.getAccountServiceList(gId,account,type);
    }

    @PostMapping("/subService")
    public boolean subjectService(@RequestBody AccountServicePerm accountServicePerm)throws SpiderException{
        return apiMarksService.subjectService(accountServicePerm);
    }

    @DeleteMapping("/unSubService")
    public boolean unSubjectService(@RequestParam String serviceId, @RequestParam String account)throws SpiderException{
        return apiMarksService.unSubjectService(serviceId,account);
    }
}
